package com.ilop.permission;

import java.util.ArrayList;
import java.util.List;

/**
 * @author skygge
 * @date 6/16/22.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：
 */
public enum PermissionEnum {

    PERMISSION_LOCATION(0, R.mipmap.icon_location, R.string.permission_location, R.string.permission_location_explain, 0),

    PERMISSION_CAMERA(1, R.mipmap.icon_camera, R.string.permission_camera, R.string.permission_camera_explain, 1),

    PERMISSION_PUSH(2, R.mipmap.icon_push, R.string.permission_push, R.string.permission_push_explain, 2);

    private final int iconRes;

    private final int titleRes;

    private final int messageRes;

    private final int permissionId;

    private final int permissionType;

    PermissionEnum(int permissionId, int iconRes, int titleRes, int messageRes, int permissionType) {
        this.iconRes = iconRes;
        this.titleRes = titleRes;
        this.messageRes = messageRes;
        this.permissionId = permissionId;
        this.permissionType = permissionType;
    }

    public int getIconRes() {
        return iconRes;
    }

    public int getTitleRes() {
        return titleRes;
    }

    public int getMessageRes() {
        return messageRes;
    }

    public int getPermissionId() {
        return permissionId;
    }

    /**
     * 查询相关权限
     * @param permissionId 自定义的权限ID,需要完全对应
     */
    public static PermissionEnum getPermissions(int permissionId) {
        for (PermissionEnum permission : PermissionEnum.values()) {
            if (permission.permissionId == permissionId) return permission;
        }
        return null;
    }

    /**
     * 查询相关权限
     * @param permissionType 权限类型
     */
    public static List<PermissionEnum> getPermissionsList(int permissionType) {
        List<PermissionEnum> list = new ArrayList<>();
        for (PermissionEnum permission : PermissionEnum.values()) {
            if (permission.permissionType == permissionType) list.add(permission);
        }
        return list;
    }
}
